Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
"SyntaxError: Cannot use import statement outside a module" error while testing a Nodejs project with Jest

So I'm working on a Nodejs project with expressjs and I'm trying to use Jest to test my apis. I've read about configuring Jest in the documentation, but I'm new to jest and it's a bit confusing. The error I'm getting :

SyntaxError: Cannot use import statement outside a module at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)

My test file:

const userController = require("../controllers/user.controller");
const router = require("../routes/user.routes");


//Testing login route
describe("POST /api/user/login", () => {
    describe("given a username and password", () => {
  
      test("should respond with a 200 status code", async () => {
        const response = await request(router).post("/login").send({
          username: "username",
          password: "password"
        })
        expect(response.statusCode).toBe(200)
      })
     })
  

  
  })
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda